<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Home\Model;
use Think\Model;

class PlatesqlModel extends Model{

    protected $tablePrefix = 'hrma_';
    protected $tableName = 'platecontent';

    /**
     * 检查是否存在相同的标题
     */
    static function check_resure_title($title = null){
        $pcontent = D('platecontent');
        $res = $pcontent->where(array('title' => $title))->count();
        return $res > 0 ? true : false;
    }

    /**
     * 获取公共资源并插入数据库
     */
    static function resure_querysql($result){
        if(!empty($result) && is_array($result)){
            foreach($result as $key => $v){
                if(!empty($v['title']) && !self::check_resure_title($v['title'])){
                    $dataList[] = array(
                        'plate_id'		=> $v['plate_id'],
                        'title'			=> $v['title'],
                        'pic'			=> $v['pic'],
                        'content'		=> $v['content'],
                        'r_date'	    => $v['r_date'],
                        'author_name'	=> $v['author_name'],
                        'r_url'			=> $v['r_url'],
                        'e_id'			=> $v['e_id'],
                        'u_date'		=> date("Y-m-d H:i:s", time()),
                        'state'         => 1
                    );
                }
            }
        }
        $pcontent = D('platecontent');
        $res = $pcontent->addAll($dataList);
        return $res ? true : false;
    }


}